package main

import (
	"fmt"
	"runtime"
	"sync"
	"sync/atomic"
)

var (
	counter  int
	counter2 int32
	wg4      sync.WaitGroup
)

func main() {
	wg4.Add(2)

	go incCounterSync(1)
	go incCounterSync(2)

	wg4.Wait()

	fmt.Println("Final Counter:", counter)
	fmt.Println("Final Counter:", counter2)
}

func incCounterSync(i int) {
	defer wg4.Done()

	for count := 1; count < 2; count++ {
		//将goroutine从线程中退出执行。放回goroutine的执行队列
		runtime.Gosched()
		atomic.AddInt32(&counter2, 1)
	}

}
